package ru.ipccenter.beans;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import ru.ipccenter.entities.Article;

/**
 * Message-Driven Bean implementation class for: ArticleMDBean
 */
@MessageDriven(
		activationConfig = { @ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Topic")
		})
public class ArticleMDBean implements MessageListener {
    @EJB
	ArticleBeanLocal ab;
    public ArticleMDBean() {
    }
	
	/**
     * @see MessageListener#onMessage(Message)
     */
    public void onMessage(Message message) {
        if (message instanceof ObjectMessage){
        	Object obj;
            try {
                obj = ((ObjectMessage) message).getObject();
                if (obj instanceof Article){
                    ab.create((Article) obj);
                }
                    
            } catch (JMSException e) {
                e.printStackTrace();
            }

        }
        
    }

}
